package com.fingard.dsp.bank.directbank.citic05.util;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileUtil
{
    public static void save2file(byte[] bytes, String filename)
            throws Exception
    {
        FileOutputStream fos = null;
        try
        {
            fos = new FileOutputStream(filename);
            fos.write(bytes); return;
        }
        finally
        {
            try
            {
                if (fos != null) {
                    fos.close();
                }
            }
            catch (Exception localException) {}
        }
    }

    public static byte[] read4file(String filename)
            throws Exception
    {
        FileInputStream fis = null;
        ByteArrayOutputStream baos = null;
        try
        {
            fis = new FileInputStream(filename);
            baos = new ByteArrayOutputStream();
            byte[] bytes = new byte[''];
            int n = 0;
            while ((n = fis.read(bytes)) > 0) {
                baos.write(bytes, 0, n);
            }
            return baos.toByteArray();
        }
        finally
        {
            try
            {
                if (fis != null) {
                    fis.close();
                }
                if (baos != null) {
                    baos.close();
                }
            }
            catch (Exception localException) {}
        }
    }
}
